Python 3.11.3 (v3.11.3:f3909b8bc8, Apr 4 2023, 20:12:10) [Clang 13.0.0 (clang-1300.0.29.30)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.26.0 -- An enhanced Interactive Python. Type '?' for help.

In [ ]:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
from IPython.display import display
In [ ]:
df = pd.read_pickle("../../data/interim/processed_data_01.pkl")
In [ ]:
set_df = df[df["set"] == 1]
plt.plot(set_df["acc_y"].reset_index(drop = True))
Out[ ]:
[<matplotlib.lines.Line2D at 0x137b29710>]
In [ ]:
for label in df["label"].unique():
    subset = df[df["label"] == label]
    fig, ax = plt.subplots()
    plt.plot(subset["acc_y"].reset_index(drop = True), label = label)
    plt.legend()
    plt.show()
In [ ]:
for label in df["label"].unique():
    subset = df[df["label"] == label]
    fig, ax = plt.subplots()
    plt.plot(subset[:100]["acc_y"].reset_index(drop = True), label = label)
    plt.legend()
    plt.show()
In [ ]:
print(plt.style.available)
mpl.style.use("seaborn-v0_8-deep")
mpl.rcParams["figure.figsize"] = (20, 5)
mpl.rcParams["figure.dpi"] = 100
['Solarize_Light2', '_classic_test_patch', '_mpl-gallery', '_mpl-gallery-nogrid', 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-v0_8', 'seaborn-v0_8-bright', 'seaborn-v0_8-colorblind', 'seaborn-v0_8-dark', 'seaborn-v0_8-dark-palette', 'seaborn-v0_8-darkgrid', 'seaborn-v0_8-deep', 'seaborn-v0_8-muted', 'seaborn-v0_8-notebook', 'seaborn-v0_8-paper', 'seaborn-v0_8-pastel', 'seaborn-v0_8-poster', 'seaborn-v0_8-talk', 'seaborn-v0_8-ticks', 'seaborn-v0_8-white', 'seaborn-v0_8-whitegrid', 'tableau-colorblind10']
In [ ]:
category_df = df.query("label == 'squat'").query("participant == 'A'").reset_index()
In [ ]:
fig, ax = plt.subplots()
category_df.groupby(["category"])["acc_y"].plot()
ax.set_xlabel("samples")
ax.set_ylabel("acc_y")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x137fa3210>
In [ ]:
participant_df = df.query("label == 'bench'").sort_values("participant").reset_index()
fig, ax = plt.subplots()
participant_df.groupby(["participant"])["acc_y"].plot()
ax.set_xlabel("samples")
ax.set_ylabel("acc_y")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x137d1a850>
In [ ]:
label = "squat"
participant = "A"
all_axis_df = df.query(f"label == '{label}'").query(f"participant == '{participant}'")
In [ ]:
fig, ax = plt.subplots()
all_axis_df[["acc_x", "acc_y", "acc_z"]].plot(ax=ax)
ax.set_xlabel("samples")
ax.set_ylabel("acc_y")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1400c4890>
In [ ]:
label = "squat"
participant = "A"
all_axis_df = df.query(f"label == '{label}'").query(f"participant == '{participant}'")
fig, ax = plt.subplots()
all_axis_df[["acc_x", "acc_y", "acc_z"]].plot()
ax.set_ylabel("acc_y")
ax.set_xlabel("samples")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1401ded90>
In [ ]:
fig, ax2 = plt.subplots()
all_axis_df[["acc_x", "acc_y", "acc_z"]].plot(ax = ax2)
ax.set_ylabel("acc_y")
ax.set_xlabel("samples")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1402c4d50>
In [ ]:
df = pd.read_pickle("../../data/interim/processed_data_01.pkl")
In [ ]:
df
Out[ ]:
acc_x acc_y acc_z gyr_x gyr_y gyr_z label category participant set
epoch (ms)
2019-01-11 15:08:05.200 0.013500 0.977000 -0.071000 -1.8904 2.4392 0.9388 bench heavy B 64
2019-01-11 15:08:05.400 -0.001500 0.970500 -0.079500 -1.6826 -0.8904 2.1708 bench heavy B 64
2019-01-11 15:08:05.600 0.001333 0.971667 -0.064333 2.5608 -0.2560 -1.4146 bench heavy B 64
2019-01-11 15:08:05.800 -0.024000 0.957000 -0.073500 8.0610 -4.5244 -2.0730 bench heavy B 64
2019-01-11 15:08:06.000 -0.028000 0.957667 -0.115000 2.4390 -1.5486 -3.6098 bench heavy B 64
... ... ... ... ... ... ... ... ... ... ...
2019-01-20 17:33:27.000 -0.048000 -1.041500 -0.076500 1.4146 -5.6218 0.2926 row medium E 71
2019-01-20 17:33:27.200 -0.037000 -1.030333 -0.053333 -2.7684 -0.5854 2.2440 row medium E 71
2019-01-20 17:33:27.400 -0.060000 -1.031000 -0.082000 2.8416 -5.1342 -0.1220 row medium E 71
2019-01-20 17:33:27.600 -0.038667 -1.025667 -0.044667 -0.2318 0.2562 1.1220 row medium E 71
2019-01-20 17:33:27.800 -0.044000 -1.034000 -0.059000 1.0980 -4.0240 0.9760 row medium E 71

9009 rows × 10 columns

In [ ]:
df.columns
Out[ ]:
Index(['acc_x', 'acc_y', 'acc_z', 'gyr_x', 'gyr_y', 'gyr_z', 'label',
       'category', 'participant', 'set'],
      dtype='object')
In [ ]:
df = df[['acc_x', 'acc_y', 'acc_z', 'gyr_x', 'gyr_y', 'gyr_z', 'participant', 'label', 'category', 'set']]
In [ ]:
df = df[['acc_x', 'acc_y', 'acc_z', 'gyr_x', 'gyr_y', 'gyr_z', 'participant', 'label', 'category', 'set']]
In [ ]:
df
Out[ ]:
acc_x acc_y acc_z gyr_x gyr_y gyr_z participant label category set
epoch (ms)
2019-01-11 15:08:05.200 0.013500 0.977000 -0.071000 -1.8904 2.4392 0.9388 B bench heavy 64
2019-01-11 15:08:05.400 -0.001500 0.970500 -0.079500 -1.6826 -0.8904 2.1708 B bench heavy 64
2019-01-11 15:08:05.600 0.001333 0.971667 -0.064333 2.5608 -0.2560 -1.4146 B bench heavy 64
2019-01-11 15:08:05.800 -0.024000 0.957000 -0.073500 8.0610 -4.5244 -2.0730 B bench heavy 64
2019-01-11 15:08:06.000 -0.028000 0.957667 -0.115000 2.4390 -1.5486 -3.6098 B bench heavy 64
... ... ... ... ... ... ... ... ... ... ...
2019-01-20 17:33:27.000 -0.048000 -1.041500 -0.076500 1.4146 -5.6218 0.2926 E row medium 71
2019-01-20 17:33:27.200 -0.037000 -1.030333 -0.053333 -2.7684 -0.5854 2.2440 E row medium 71
2019-01-20 17:33:27.400 -0.060000 -1.031000 -0.082000 2.8416 -5.1342 -0.1220 E row medium 71
2019-01-20 17:33:27.600 -0.038667 -1.025667 -0.044667 -0.2318 0.2562 1.1220 E row medium 71
2019-01-20 17:33:27.800 -0.044000 -1.034000 -0.059000 1.0980 -4.0240 0.9760 E row medium 71

9009 rows × 10 columns

In [ ]:
set_df = df[df["set"] == 1]
plt.plot(set_df["acc_y"].reset_index(drop = True))
Out[ ]:
[<matplotlib.lines.Line2D at 0x14036ae10>]
In [ ]:
for label in df["label"].unique():
    subset = df[df["label"] == label]
    fig, ax = plt.subplots()
    plt.plot(subset["acc_y"].reset_index(drop = True), label = label)
    plt.legend()
    plt.show()
In [ ]:
for label in df["label"].unique():
    subset = df[df["label"] == label]
    fig, ax = plt.subplots()
    plt.plot(subset[:100]["acc_y"].reset_index(drop = True), label = label)
    plt.legend()
    plt.show()
In [ ]:
mpl.style.use("seaborn-v0_8-deep")
mpl.rcParams["figure.figsize"] = (20, 5)
mpl.rcParams["figure.dpi"] = 100
In [ ]:
category_df = df.query("label == 'squat'").query("participant == 'A'").reset_index()
In [ ]:
fig, ax = plt.subplots()
category_df.groupby(["category"])["acc_y"].plot()
ax.set_xlabel("samples")
ax.set_ylabel("acc_y")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x137bfcd50>
In [ ]:
participant_df = df.query("label == 'bench'").sort_values("participant").reset_index()
fig, ax = plt.subplots()
participant_df.groupby(["participant"])["acc_y"].plot()
ax.set_xlabel("samples")
ax.set_ylabel("acc_y")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x140426710>
In [ ]:
label = "squat"
participant = "A"
all_axis_df = df.query(f"label == '{label}'").query(f"participant == '{participant}'")
fig, ax2 = plt.subplots()
all_axis_df[["acc_x", "acc_y", "acc_z"]].plot(ax = ax2)
ax.set_ylabel("acc_y")
ax.set_xlabel("samples")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1404d7510>
In [ ]:
labels = df["label"].unique()
participants = df["participant"].unique()
In [ ]:
for label in labels:
    for participant in participants:
        all_axis_df = (
            df.query(f"label == '{label}'")
            .query(f"participant == '{participant}'")
            .reset_index()
        )
    fig, ax = plt.subplots()
    all_axis_df[["acc_x", "acc_y", "acc_z"]].plot(ax = ax)
    ax.set_ylabel("acc_y")
    ax.set_xlabel("samples")
    plt.title(f"{label} ({participant})".title())
    plt.legend()
In [ ]:
for label in labels:
    for participant in participants:
        all_axis_df = (
            df.query(f"label == '{label}'")
            .query(f"participant == '{participant}'")
            .reset_index()
        )
        if len(all_axis_df) > 0:
            fig, ax = plt.subplots()
            all_axis_df[["acc_x", "acc_y", "acc_z"]].plot(ax = ax)
            ax.set_ylabel("acc_y")
            ax.set_xlabel("samples")
            plt.title(f"{label} ({participant})".title())
            plt.legend()
<ipython-input-30-013967daef1c>:9: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). Consider using `matplotlib.pyplot.close()`.
  fig, ax = plt.subplots()
In [ ]:
for label in labels:
    for participant in participants:
        all_axis_df = (
            df.query(f"label == '{label}'")
            .query(f"participant == '{participant}'")
            .reset_index()
        )
        if len(all_axis_df) > 0:
            fig, ax = plt.subplots()
            all_axis_df[["gyr_x", "gyr_y", "gyr_z"]].plot(ax = ax)
            ax.set_ylabel("gyr_y")
            ax.set_xlabel("samples")
            plt.title(f"{label} ({participant})".title())
            plt.legend()
<ipython-input-31-9f970ca87cf7>:9: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). Consider using `matplotlib.pyplot.close()`.
  fig, ax = plt.subplots()
In [ ]:
label = "row"
participant = "A"
all_axis_df = df.query(f"label == '{label}'").query(f"participant == '{participant}'")
fig, ax = plt.subplots()
all_axis_df[["acc_x", "acc_y", "acc_z"]].plot(ax = ax)
ax.set_ylabel("acc_y")
ax.set_xlabel("samples")
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x137d39290>
In [ ]:
label = "row"
participant = "A"
df_combine = (
    df.query(f"label == '{label}'")
    .query(f"participant == '{participant}'")
    .reset_index(drop = True)
)
In [ ]:
df_combine
Out[ ]:
acc_x acc_y acc_z gyr_x gyr_y gyr_z participant label category set
0 0.109000 -0.935667 -0.092333 5.24380 -3.82920 2.2806 A row heavy 81
1 0.129000 -1.174000 -0.114500 13.47560 -3.81700 4.6462 A row heavy 81
2 0.136333 -1.295000 -0.118667 27.29260 -7.97560 -5.4148 A row heavy 81
3 0.171000 -1.221500 0.049000 21.90240 -3.80500 -15.5244 A row heavy 81
4 0.148000 -0.871333 0.136000 19.07340 -3.59760 1.8050 A row heavy 81
... ... ... ... ... ... ... ... ... ... ...
80 0.178333 -0.947000 0.225333 -30.34160 14.63400 14.1586 A row heavy 84
81 0.126500 -1.156000 0.160500 -30.25620 3.69500 23.0004 A row heavy 84
82 0.047000 -1.204000 0.025000 -20.51220 6.54860 5.0244 A row heavy 84
83 0.034000 -1.071000 -0.027000 0.34140 -2.25600 0.4514 A row heavy 84
84 0.037000 -1.022500 -0.004500 -1.20425 -3.21625 1.1585 A row heavy 84

85 rows × 10 columns

In [ ]:
fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
In [ ]:
label = "row"
participant = "A"
df_combine = (
    df.query(f"label == '{label}'")
    .query(f"participant == '{participant}'")
    .reset_index(drop = True)
)
In [ ]:
fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
In [ ]:
fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
In [ ]:
fig, ax
Out[ ]:
(<Figure size 2000x1000 with 2 Axes>,
 array([<Axes: >, <Axes: >], dtype=object))
In [ ]:
fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
df_combine[["acc_x", "acc_y", "acc_z"]].plot(ax = ax[0])
df_combine[["gyr_x", "gyr_y", "gyr_z"]].plot(ax = ax[1])
Out[ ]:
<Axes: >
In [ ]:
ax[0].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
ax[1].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
ax[1].set_xlabel("samples")
Out[ ]:
Text(0.5, 4.4444444444444375, 'samples')
In [ ]:
fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
df_combine[["acc_x", "acc_y", "acc_z"]].plot(ax = ax[0])
df_combine[["gyr_x", "gyr_y", "gyr_z"]].plot(ax = ax[1])
#add some styling to the plots

ax[0].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
ax[1].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
ax[1].set_xlabel("samples")
Out[ ]:
Text(0.5, 0, 'samples')
In [ ]:
labels = df["label"].unique()
participants = df["participant"].unique()
for label in labels:
    for participant in participants:
        df_combine = (
            df.query(f"label == '{label}'")
            .query(f"participant == '{participant}'")
            .reset_index()
        )
        if len(df_combine) > 0:
            fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
            df_combine[["acc_x", "acc_y", "acc_z"]].plot(ax = ax[0])
            df_combine[["gyr_x", "gyr_y", "gyr_z"]].plot(ax = ax[1])
            #add some styling to the plots
            ax[0].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
            ax[1].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
            ax[1].set_xlabel("samples")
<ipython-input-43-56f9c59c25b5>:11: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). Consider using `matplotlib.pyplot.close()`.
  fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
In [ ]:
for label in labels:
    for participant in participants:
        df_combine = (
            df.query(f"label == '{label}'")
            .query(f"participant == '{participant}'")
            .reset_index()
        )
        if len(df_combine) > 0:
            fig, ax = plt.subplots(nrows = 2, sharex = True, figsize = (20, 10))
            df_combine[["acc_x", "acc_y", "acc_z"]].plot(ax = ax[0])
            df_combine[["gyr_x", "gyr_y", "gyr_z"]].plot(ax = ax[1])
            #add some styling to the plots
            ax[0].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
            ax[1].legend(loc = "upper center", bbox_to_anchor = (0.5, 1.15), ncol = 3, fancybox = True, shadow = True)
            ax[1].set_xlabel("samples")
            plt.savefig(f"../../reports/figures/{label.title()} ({participant}).png")
            plt.show()